<?php

namespace Shared\Extensions\Twig;

/**
 * Description of Path
 *
 * @author nofear
 */
class Widget extends \Twig_Extension {

    public function getFunctions() {
        return array(
            'widget' => new \Twig_Function_Method($this, 'widget'),
        );
    }

    public function widget($widget, array $config = null) {
        if (!class_exists($widget)) {
            throw new \Exception(sprintf('Widget "%s" doeson\'t exists or is not callable', $widget));
        }
        
        $Widget = new $widget($config);

        return $Widget->paste();
    }

    public function getName() {
        return 'widget';
    }

}
